package com.collect.discord.web.controller;

import com.collect.common.utils.AjaxResult;
import com.collect.discord.web.domain.SensitiveWord;
import com.collect.discord.web.service.ISensitiveWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 知识库Controller
 *
 * @author hky
 */
@RestController
@RequestMapping("/sensitive")
public class SensitiveWordController
{
    @Autowired
    private ISensitiveWordService sensitiveWordService;
    /**
     * 查询知识库列表
     */

    @GetMapping("/list")
    public AjaxResult list(SensitiveWord gatherKnowledge)
    {
        List<SensitiveWord> list = sensitiveWordService.getSensitiveWordList(gatherKnowledge);
        return AjaxResult.success(list);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody SensitiveWord sensitiveWord)
    {
        return AjaxResult.toAjax(sensitiveWordService.saveSensitiveWord(sensitiveWord));
    }

    @PutMapping("/update")
    public AjaxResult edit(@RequestBody SensitiveWord sensitiveWord)
    {
        return AjaxResult.toAjax(sensitiveWordService.updateSensitiveWord(sensitiveWord));
    }

	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {

        return AjaxResult.toAjax(sensitiveWordService.delSensitiveWord(Arrays.asList(ids)));
    }

    @GetMapping("/getDic")
    public void getDic(HttpServletResponse httpServletResponse) throws IOException {
        sensitiveWordService.getDic(false,httpServletResponse);
    }
    @GetMapping("/getStopDic")
    public void getStopDic(HttpServletResponse httpServletResponse) throws IOException {
        sensitiveWordService.getDic(true,httpServletResponse);
    }


}
